﻿using Microsoft.Build.Framework;
using Microsoft.Build.Utilities;
using NuGet.MSBuild.Tools.Helpers;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;

namespace NuGet.MSBuild.Tools
{
    public class ResolveNuGetToolPath : Task
    {
        [Required]
        public string SolutionPath { get; set; }

        [Output]
        public string ToolPath { get; set; }

        public override bool Execute()
        {
            string fileName = Path.Combine(this.SolutionPath, SpecialFolder.NuGetRoot, SpecialFile.Packages);
            if (File.Exists(fileName))
            {
                NuGetPathResolver resolver = new NuGetPathResolver()
                {
                    SolutionPath = this.SolutionPath
                };

                string path = resolver.GetPath(fileName);
                if (!string.IsNullOrEmpty(path))
                {
                    this.ToolPath = path;
                }
            }

            return true;
        }
    }
}
